'use strict';

const Service = require('egg').Service;

class ListService extends Service {
    async add(nick_name,phone,tags,role,id_card,address,info,end){
        let time = new Date();
        await this.app.mysql.query('insert into list (nick_name,phone,tags,role,id_card,address,info,create_time,end) values (?,?,?,?,?,?,?,?,?)',[nick_name,phone,tags,role,id_card,address,info,time,end])
    }    
    async del(id){
        await this.app.mysql.query('delete from list where id=?',[id])
    }
    async list(pagenum,limit){
        let startIndex = (pagenum-1)*limit;
        //分页sql limit 起始的下标,每页条数
        // 1 0  2

        // 2 2  2

        // 3 4  2
        return await this.app.mysql.query(`select * from list limit ${startIndex},${limit}`)
    }

    async total(){
        return await this.app.mysql.query('select count(*) from list')
    }
    async edit(nick_name,phone,tags,role,id_card,address,info,end,id){
        await this.app.mysql.query('update list set nick_name=?,phone=?,tags=?,role=?,id_card=?,address=?,info=?,end=? where id=?',[nick_name,phone,tags,role,id_card,address,info,end,id])
    }
}

module.exports = ListService;
